<template>
	<el-row>
		<el-col :span="12">
			<el-table :data="posts" border style="width: auto">
				<el-table-column prop="postDepartment" label="Name" width="180" />
				<el-table-column prop="postName" label="Date" width="180" />
			</el-table>
		</el-col>
		<el-col :span="12">
			<div class="grid-content ep-bg-purple-light" />
			<el-form :model="post" label-width="120px">

				<el-form-item label="所属部门">
					<el-select v-model="post.postDepartment" placeholder="please select your zone">
						<el-option label="业务部" value="业务部" />
						<el-option label="人事部" value="人事部" />
						<el-option label="财务部" value="财务部" />
						<el-option label="项目部" value="项目部" />
					</el-select>
				</el-form-item>

				<el-form-item label="职位名称">
					<el-input v-model="post.postName" />
				</el-form-item>
				<el-button type="primary" @click="onSubmit"> 添加 </el-button>
			</el-form>
		</el-col>
	</el-row>
</template>

<script>
	import {
		reactive
	} from 'vue'

	import qs from 'qs'
	export default {
		data() {
			return {
				post: {
					postName: '',
					postDepartment: '',
				},
				posts: [],
			}
		},
		methods: {
			onSubmit() {
				let that = this
				let str = qs.stringify(this.post)
				console.log(this.post)
				this.$axios.get("http://localhost:8080/post/insert?" + str).then(function(res) {
					console.log(res);
					that.getAllPost()
				})
			},
			getAllPost() {
				let that = this
				let str = ''
				this.$axios.get("http://localhost:8080/post/search?" + str).then(function(res) {
					console.log(res);
					that.posts = res.data
					console.log(that.posts)
				})
			}
		},
		created() {
			this.getAllPost()
		}

	}
</script>
